From 74a00319ddeb32470d86d99a7e391ad10c333a4c Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 3 Mar 2023 21:10:39 +0000 Subject: [PATCH] a11y: Use weak references for GtkATContext cached accessibles The accessible objects already own the GtkATContext, let's avoid a reference cycle. --- gtk/gtkatcontext.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/gtk/gtkatcontext.c b/gtk/gtkatcontext.c index e4e66e82aa..2ae924cc92 100644 --- a/gtk/gtkatcontext.c +++ b/gtk/gtkatcontext.c @@ -85,8 +85,19 @@ gtk_at_context_dispose (GObject *gobject) gtk_at_context_unrealize (self); - g_clear_object (&self->accessible_parent); - g_clear_object (&self->next_accessible_sibling); + if (self->accessible_parent != NULL) + { + g_object_remove_weak_pointer (G_OBJECT (self->accessible_parent), + (gpointer *) &self->accessible_parent); + self->accessible_parent = NULL; + } + + if (self->next_accessible_sibling != NULL) + { + g_object_remove_weak_pointer (G_OBJECT (self->next_accessible_sibling), + (gpointer *) &self->next_accessible_sibling); + self->next_accessible_sibling = NULL; + } G_OBJECT_CLASS (gtk_at_context_parent_class)->dispose (gobject); } @@ -479,7 +490,17 @@ gtk_at_context_set_accessible_parent (GtkATContext *self, { g_return_if_fail (GTK_IS_AT_CONTEXT (self)); - g_set_object (&self->accessible_parent, parent); + if (self->accessible_parent != parent) + { + if (self->accessible_parent != NULL) + g_object_remove_weak_pointer (G_OBJECT (self->accessible_parent), + (gpointer *) &self->accessible_parent); + + self->accessible_parent = parent; + if (self->accessible_parent != NULL) + g_object_add_weak_pointer (G_OBJECT (self->accessible_parent), + (gpointer *) &self->accessible_parent); + } } /*< private > @@ -511,7 +532,18 @@ gtk_at_context_set_next_accessible_sibling (GtkATContext *self, { g_return_if_fail (GTK_IS_AT_CONTEXT (self)); - g_set_object (&self->next_accessible_sibling, sibling); + if (self->next_accessible_sibling != sibling) + { + if (self->next_accessible_sibling != NULL) + g_object_remove_weak_pointer (G_OBJECT (self->next_accessible_sibling), + (gpointer *) &self->next_accessible_sibling); + + self->next_accessible_sibling = sibling; + + if (self->next_accessible_sibling != NULL) + g_object_add_weak_pointer (G_OBJECT (self->next_accessible_sibling), + (gpointer *) &self->next_accessible_sibling); + } } /*< private > -- 2.30.2